#
from .manage import Base
from sqlalchemy import Column, String


class App(Base):
    """app表"""

    __tablename__ = "app"
    __table_args__ = {"extend_existing": True}

    app_id = Column(String, primary_key=True)
    # 前一个版本的id，'0'时为第一个版本
    before_id = Column(String, nullable=True)
    alias = Column(String, nullable=True)
    file_name = Column(String, nullable=True)
    node = Column(String, nullable=True)
    create_time = Column(String, nullable=True)
    deploy_time = Column(String, nullable=True)
    status = Column(String, nullable=True)
    notes = Column(String, nullable=True)
    version = Column(String, nullable=True)
    run_path = Column(String, nullable=True)
    project = Column(String, nullable=True)
    port = Column(String, nullable=True)
    team = Column(String, nullable=True)
    modules = Column(String, nullable=True)
    runner = Column(String, nullable=True)
    runner_version = Column(String, nullable=True)
    create_user = Column(String, nullable=True)
    source = Column(String, nullable=True)
    time_dir = Column(String, nullable=True)
    nginx_conf = Column(String, nullable=True)
    # group = Column(String, nullable=True)


class App_backup(Base):
    """app表"""

    __tablename__ = "app_backup"
    __table_args__ = {"extend_existing": True}

    back_id = Column(String, primary_key=True)
    # 版本信息记录
    app_id = Column(String, nullable=True)
    before_id = Column(String, nullable=True)
    alias = Column(String, nullable=True)
    file_name = Column(String, nullable=True)
    node = Column(String, nullable=True)
    create_time = Column(String, nullable=True)
    deploy_time = Column(String, nullable=True)
    notes = Column(String, nullable=True)
    version = Column(String, nullable=True)
    run_path = Column(String, nullable=True)
    port = Column(String, nullable=True)
    project = Column(String, nullable=True)
    team = Column(String, nullable=True)
    modules = Column(String, nullable=True)
    runner = Column(String, nullable=True)
    runner_version = Column(String, nullable=True)
    create_user = Column(String, nullable=True)
    source = Column(String, nullable=True)
    time_dir = Column(String, nullable=True)
    nginx_conf = Column(String, nullable=True)
    # group = Column(String, nullable=True)


class C_records(Base):
    """控制、修改记录，C表示control和change"""

    __tablename__ = "c_records"
    __table_args__ = {"extend_existing": True}

    uid = Column(String, primary_key=True)
    user = Column(String, nullable=True)
    type_ = Column(String, nullable=True)
    app_id = Column(String, nullable=True)
    behavior = Column(String, nullable=True)
    run_command = Column(String, nullable=True)
    execute_time = Column(String, nullable=True)
    result = Column(String, nullable=True)
    info = Column(String, nullable=True)
    project = Column(String, nullable=True)
    team = Column(String, nullable=True)


class Run_records(Base):
    """App的运行记录和回滚后的运行记录"""

    __tablename__ = "run_records"
    __table_args__ = {"extend_existing": True}

    uid = Column(String, primary_key=True)
    alias = Column(String, nullable=True)
    user = Column(String, nullable=True)
    source = Column(String, nullable=True)
    app_id = Column(String, nullable=True)
    start_time = Column(String, nullable=True)
    end_time = Column(String, nullable=True)
    log_path = Column(String, nullable=True)
    inpara = Column(String, nullable=True)
    port = Column(String, nullable=True)
    notes = Column(String, nullable=True)
    version = Column(String, nullable=True)
    run_path = Column(String, nullable=True)
    runner = Column(String, nullable=True)
    runner_version = Column(String, nullable=True)
    process_name = Column(String, nullable=True)
    pid = Column(String, nullable=True)


class Deploy_records(Base):
    """Web App的部署记录"""

    __tablename__ = "deploy_records"
    __table_args__ = {"extend_existing": True}

    uid = Column(String, primary_key=True)
    app_id = Column(String, nullable=True)
    alias = Column(String, nullable=True)
    file_name = Column(String, nullable=True)
    node = Column(String, nullable=True)
    status = Column(String, nullable=True)
    create_time = Column(String, nullable=True)
    deploy_time = Column(String, nullable=True)
    log_path = Column(String, nullable=True)
    keepalive = Column(String, nullable=True)
    notes = Column(String, nullable=True)
    version = Column(String, nullable=True)
    inpara = Column(String, nullable=True)
    run_path = Column(String, nullable=True)
    pid = Column(String, nullable=True)
    port = Column(String, nullable=True)
    project = Column(String, nullable=True)
    team = Column(String, nullable=True)
    modules = Column(String, nullable=True)
    runner = Column(String, nullable=True)
    runner_version = Column(String, nullable=True)
    create_user = Column(String, nullable=True)
    source = Column(String, nullable=True)


class Resource_usage_records(Base):
    """资源使用记录表"""

    __tablename__ = "resource_usage_records"
    __table_args__ = {"extend_existing": True}

    uid = Column(String, primary_key=True)
    app_id = Column(String, nullable=True)
    alias = Column(String, nullable=True)
    file_name = Column(String, nullable=True)
    node = Column(String, nullable=True)
    timestamp = Column(String, nullable=True)
    cpu_usage = Column(String, nullable=True)
    memory_usage = Column(String, nullable=True)
    disk_usage = Column(String, nullable=True)
    network_usage = Column(String, nullable=True)
